package com.evildog.workspace.invest.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryBO;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryListBO;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryPageBO;
import com.evildog.workspace.invest.application.convert.BillTypeCategoryConvert;
import com.evildog.workspace.invest.application.model.BillTypeCategoryListParam;
import com.evildog.workspace.invest.application.model.BillTypeCategoryPageParam;
import com.evildog.workspace.invest.application.model.BillTypeCategoryParam;
import com.evildog.workspace.invest.application.service.BillTypeCategoryService;
import com.evildog.workspace.invest.application.vo.BillTypeCategoryListVO;
import com.evildog.workspace.invest.application.vo.BillTypeCategoryPageVO;
import com.evildog.workspace.invest.application.vo.BillTypeCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * billTypeCategory Controller
    账单类型分类(居家)
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/bill-type-categories")
@AllArgsConstructor
@Api(tags = "billTypeCategory相关接口")
public class BillTypeCategoryController {

    private BillTypeCategoryService billTypeCategoryService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody BillTypeCategoryParam billTypeCategoryParam) {
        return ResultGenerator.status(billTypeCategoryService.save(BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(billTypeCategoryService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(billTypeCategoryService.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody BillTypeCategoryParam billTypeCategoryParam) {
        return ResultGenerator.status(billTypeCategoryService.updateById(id, BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<BillTypeCategoryVO> getById(@PathVariable("id") Long id) {
        BillTypeCategoryBO billTypeCategoryBO = billTypeCategoryService.getDetailById(id);
        return ResultGenerator.success(BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<BillTypeCategoryPageVO>> getPageList(BillTypeCategoryPageParam billTypeCategoryPageParam, PageQuery query){
        PagedResult<BillTypeCategoryPageBO> billTypeCategoryPageBO = billTypeCategoryService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(billTypeCategoryPageParam),
                        BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryPageParam));
        return ResultGenerator.success(BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryPageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<BillTypeCategoryListVO>> getList(BillTypeCategoryListParam billTypeCategoryListParam){
        List<BillTypeCategoryListBO> billTypeCategoryListBO = billTypeCategoryService.getList(
                        QueryConditionUtils.getQueryCondition(billTypeCategoryListParam),
                        BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryListParam));
        return ResultGenerator.success(BillTypeCategoryConvert.INSTANCE.convertVoList(billTypeCategoryListBO));
    }

}